package com.health.webservices.dzjmjkkxml;

import java.io.StringReader;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import com.health.model.DZJMJKKSQCodeImageBean;
import com.health.model.DZJMJKKXQcodeBean;

import android.util.Log;
import android.util.Xml;

public class PullDZJMJKKSQCodeImageParser implements DZJMJKKSQCodeImageParser {
	@Override
	public DZJMJKKSQCodeImageBean parse(String xmlData) throws Exception {
		DZJMJKKSQCodeImageBean ecg = null;

		// XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
		// XmlPullParser parser = factory.newPullParser();

		XmlPullParser parser = Xml.newPullParser(); // 由android.util.Xml创建一个XmlPullParser实例
		// parser.setInput(is, "UTF-8"); // 设置输入流 并指明编码方式
		try {
			parser.setInput(new StringReader(xmlData));
		} catch (XmlPullParserException e) {
			e.printStackTrace();
		}

		int eventType = parser.getEventType();
		while (eventType != XmlPullParser.END_DOCUMENT) {
			String nodeName = parser.getName();
			switch (eventType) {
			case XmlPullParser.START_DOCUMENT:
				ecg = new DZJMJKKSQCodeImageBean();
				break;
			case XmlPullParser.START_TAG:
				Log.w("eeeeeepull解析------", "ee" + parser.getName());
//				//<response>
//				<result> success or failure</result>
//				<desc>申请信息成功or失败</desc>
//				<ehc_cardinfo>
//					<qr_code></qr_code>
//			        <qr_code_imgtext></qr_code_imgtext>
//			        <qr_code_imgurl></qr_code_imgurl>
//				</ehc_cardinfo>
//			</response>


				if ("result".equals(nodeName)) {
					eventType = parser.next();
					ecg.setResult(parser.getText());

				} else if ("desc".equals(nodeName)) {
					eventType = parser.next();
					ecg.setDesc(parser.getText());

				} else if ("qr_code".equals(nodeName)) {
					eventType = parser.next();
					ecg.setQr_code(parser.getText());

				} else if ("qr_code_imgtext".equals(nodeName)) {
					eventType = parser.next();
					ecg.setQr_code_imgtext(parser.getText());

				} else if ("qr_code_imgurl".equals(nodeName)) {
					eventType = parser.next();
					ecg.setQr_code_imgurl(parser.getText());

				}  
			case XmlPullParser.END_TAG:
				if ("response".equals(nodeName)) {
					Log.w("eeeeeeeeee000000", ecg.toString());

				}
				break;
			}
			eventType = parser.next();
		}
		return ecg;
	}


	@Override
	public String serialize(DZJMJKKSQCodeImageBean ecg) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}

}
